package demo.api;

import demo.service.DemoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * @author hankChan
 *         2017/7/21 0021.
 */
@Controller
public class DemoController {

    @Autowired
    DemoService demoService;

    @RequestMapping("/api/health")
    public @ResponseBody String health() {
        return "health checked: " + new Date().toString();
    }

    @RequestMapping("/api/get/{id}")
    public @ResponseBody  HashMap<String, Object> get(@PathVariable("id") String id) {
        HashMap<String, Object> result = new HashMap<>();
        result.put("isSuccess", true);
        result.put("result", demoService.get(id));
        result.put("callbackId", id);
        return result;
    }
}
